package m.permission.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import m.Config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ming
 * @date 2014年2月20日下午8:54:55
 */
public class BaseInfo {
	private static Logger log = LoggerFactory.getLogger(BaseInfo.class);
	private static Map<String,List> infoMap;
	
	private String type;
	private String key;
	private String value;
	private Integer index;
	
	
	public static List<BaseInfo> get(String type){
		if(infoMap==null){
			infoMap=loadByFile();
		}
		List list=infoMap.get(type);
		if(list==null||list.size()==0){
			log.error("查找baseInfo出错:"+type);
			return new ArrayList();
		}
		return infoMap.get(type);
	}


	public static Map<String, List> loadByFile() {
		Properties p=Config.readProperties(Config.BASE_INFO_PATH);
		Map map=new HashMap();
		Set<Entry<Object, Object>> en=p.entrySet();
		for(Entry e:en){
			log.info("新增baseInfo:"+e.getKey()+"="+e.getValue());
			String[] str=(e.getKey()+"").split("\\.");
			List list=(List) map.get(str[0]);
			if(list==null){
				list=new ArrayList();
			}
			BaseInfo b=new BaseInfo();
			b.type=str[0];
			b.key=str[1];
			b.value=e.getValue()+"";
			b.index=list.size();
			list.add(b);
			map.put(b.type, list);
		}
		return map;
	}

	public String getKey() {
		return key;
	}

	public String getValue() {
		return value;
	}


	public Integer getIndex() {
		return index;
	}


	public String getType() {
		return type;
	}
	
	
}




